package cn.fsd.exception;

import cn.fsd.vo.ResultBean;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = {AppException.class})
    @ResponseBody
    public <T> ResultBean<T> exceptionHandler(AppException e){
        //这里先判断拦截到的异常是不是我们自己定义的异常类型
        if(e != null){
            return ResultBean.error(e.getCode(), e.getMsg());
        }
        return ResultBean.error("服务器内部异常");
    }

}
